package com.two.commodityorder.controller;
//添加商品
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.two.commodityorder.service.CommodityService;
import com.two.commodityorder.service.impl.CommodityServiceImpl;

import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/addCommodityServlet.do")
public class AddCommodityServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求对象的编码格式
    	req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("UTF-8");
        // 获取传入的商品名称和价格
        String commodityName = req.getParameter("commodityName");
        String price = req.getParameter("price");
        CommodityService service = new CommodityServiceImpl();
        boolean result = service.AddCommodity(commodityName,price);
        System.out.println("添加结果：" + result);
		req.getRequestDispatcher("view/productcontrol/chaxun.html").forward(req, resp);
    }
}
